from bs4 import BeautifulSoup

import requests

url="https://www.baidu.com/"
ua={
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36'
}
req=requests.get(url,headers=ua)
html=req.content.decode('utf-8')
soup=BeautifulSoup(html,'lxml')
#print("输出：", soup.prettify())
#print("标签:",soup.head)
#print("获取title标签：",soup.title)
#print("获取a标签：",soup.body.a)
# print("所有为a的：",soup.find_all('a'))
# print(type(soup.find_all('a')))
# print("所有为a个数：",len(soup.find_all('a')))
# print("soup的name:",soup.name)
# print("a标签的name：",soup.a.name)
tag=soup.a
# print("tag的name：",tag.name)
print("tag的内容：",tag)
print("tag对象的全部属性：",tag.sttrs)
print("href属性的值:",tag.attrs['href'])